<?php

class orders_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'orders';
    }

    function find_order_by_id($order_ID) {
        $q = "
		SELECT * 
		FROM orders
		WHERE ID = $order_ID";
        $res = $this->db->query($q)->result_array();
        return $res;
    }

    function find_orders_by_supplier_id($supplier_ID){


        $q = "
		SELECT orders.*, suppliers.name as supplier_name
		FROM orders
		LEFT JOIN suppliers
		ON orders.supplier_ID = suppliers.ID
		WHERE supplier_ID = $supplier_ID
		";

        $res = $this->db->query($q)->result_array();
        return $res;
        //SELECT * FROM orders LEFT JOIN suppliers ON orders.supplier_ID = suppliers.ID WHERE supplier_ID = 1
    }

    function list_all_orders(){


        $q = "
		SELECT orders.*, suppliers.name as supplier_name
		FROM orders
		LEFT JOIN suppliers
		ON orders.supplier_ID = suppliers.ID
		WHERE 1
		";

        $res = $this->db->query($q)->result_array();
        return $res;
        //SELECT * FROM orders LEFT JOIN suppliers ON orders.supplier_ID = suppliers.ID WHERE supplier_ID = 1
    }


    function  find_by_id($order_ID){
        $q = "
		SELECT *
		FROM orders
		WHERE ID = $order_ID
		";

        $res = $this->db->query($q)->row_array();
        return $res;
        //SELECT * FROM orders LEFT JOIN suppliers ON orders.supplier_ID = suppliers.ID WHERE supplier_ID = 1
    }
}

?>
